import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Description： TODO
 * Author： 王多鱼
 * CreateTime： 2021/6/21 19:32
 **/
public class MetaspaceOOMtest {
    static class OOMTest{ }
    public static void main(String[] args) {
        int i=0;//模拟计数多少次以后发生异常
        try {
            while (true){
                i++;
                Enhancer enhancer = new Enhancer();
                enhancer.setSuperclass(OOMTest.class);
                enhancer.setUseCache(false);
                enhancer.setCallback(new MethodInterceptor() {
                    @Override
                    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                        return methodProxy.invokeSuper(0,args);
                    }
                });
                enhancer.create();
            }
        } catch (Exception e) {

            e.printStackTrace();
        }finally {
            System.out.println("******多少次后发生了异常"+i);
        }
    }
}
